<template>
  <div id="app">
    <h3>Element表单</h3>
    <hr/>
    <!-- <el-form :model="model" :rules="rules" ref="loginForm">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="model.username" autocomplete="off"></el-input>
        </el-form-item>
         <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="model.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('loginForm')">提交</el-button>
        </el-form-item>
    </el-form> -->
    <my-form :model="model" :rules="rules" ref="loginForm">
        <my-form-item label="用户名" prop="username">
          <my-input v-model="model.username" autocomplete="off"></my-input>
        </my-form-item>
         <my-form-item label="密码" prop="password">
          <my-input type="password" v-model="model.password" autocomplete="off"></my-input>
        </my-form-item>
        <my-form-item>
          <el-button type="primary" @click="submitForm('loginForm')">提交</el-button>
        </my-form-item>
    </my-form>
  </div>
</template>

<script>
// import HelloWorld from './components/HelloWorld.vue'
import MyForm from "./components/MyForm"
import MyFormItem from "./components/MyFormItem"
import MyInput from "./components/MyInput"
export default {
  name: 'app',
  data(){
    return {
      model:{username:'tom',password:""},
      rules:{
        username:[
          { required: true, message: "请输入用户名" },
          {min: 6,max:10,message:'请输入6~10的用户名'}
          ],
        password:[{required:true,message:"请输入密码"}]
      }
    }
  },
  methods:{
    submitForm(form){
      this.$refs[form].validate(valid=>{
        if(valid){
          alert("请求登录")
        }else{
          alert("校验失败")
        }
      })
    }
  },
  components: {
    //HelloWorld
    MyForm,
    MyFormItem,
    MyInput
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
